package com.neusoft.crm.controller;

import com.neusoft.crm.mapper.ClientServerMapper;
import com.neusoft.crm.po.ClientServer;
import com.neusoft.crm.service.ClientServerService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
public class ClientServerController {
    @Resource
    private ClientServerService clientServerService;
    @Resource
    private ClientServerMapper clientServerMapper;

    @RequestMapping("/selectAllService")
    @Transactional
    public List<ClientServer> selectAllService(){
        return clientServerService.selectAllService();
    }

    @RequestMapping("/serverAssign")
    public boolean serviceAssign(@RequestBody ClientServer clientServer){
//        SysUser sysUser =new SysUser();
//        clientServer.setServerDueId(sysUser.getUserId());
        clientServer.setServerStatus(2);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date currentDate = new Date();
        String formattedDate = sdf.format(currentDate);
        clientServer.setServerDueDate(formattedDate);
        return clientServerService.updateById(clientServer);
    }

    @RequestMapping("/createServer")
    public int createServer(@RequestBody ClientServer clientServer){
        clientServer.setServerStatus(1);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date currentDate = new Date();
        String formattedDate = sdf.format(currentDate);
        clientServer.setServerCreateDate(formattedDate);
        return clientServerMapper.insert(clientServer);
    }

    @RequestMapping("/selectAllServiceBySysUserUserId")
    public List<ClientServer> selectAllServiceBySysUserUserId(){
        return clientServerMapper.selectAllServiceBySysUserUserId();
    }

    @RequestMapping("/saveServerDealEdit")
    public int saveServerDealEdit(@RequestBody ClientServer clientServer){
        clientServer.setServerStatus(3);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date currentDate = new Date();
        String formattedDate = sdf.format(currentDate);
        clientServer.setProcessingDate(formattedDate);
        return clientServerMapper.updateById(clientServer);
    }

    @RequestMapping("/selectAllServiceByUserIdFeedback")
    public List<ClientServer> selectAllServiceByUserIdFeedback(){
        return clientServerMapper.selectAllServiceByUserIdFeedback();
    }

    @RequestMapping("/saveServerFeedbackEditInfo")
    public int saveServerFeedbackEditInfo(@RequestBody ClientServer clientServer){
        clientServer.setServerStatus(4);
        return clientServerMapper.updateById(clientServer);
    }

}
